package com.xlh.server.protocol.support.json;

import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.LinearLayout;

import com.xlh.Utils.FontHandler;
import com.xlh.Utils.GsonManager;
import com.xlh.bean.ProtocolObject.Base;
import com.xlh.interf.IActivity;
import com.xlh.interf.ITakeMessage;

import net.nightwhistler.htmlspanner.HtmlSpanner;

/**
 * Created by Administrator on 2018/7/2.
 */

public class OpenLongBoxServer implements ITakeMessage {

    private IActivity atv;
    private String hasType = "openLongBox";
    private Base protccoObj;
    public OpenLongBoxServer(IActivity atv){
        this.atv = atv;


    }

    @Override
    public void takeMessage(String t,String s){

        if(!t.equals(this.hasType)) return;

        protccoObj =  GsonManager.gsmgr.jsonToAnyObject(s, Base.class);

        if(protccoObj==null || protccoObj.getText().equals("")) return;

        bulidView(protccoObj.getText());

    }

    @Override
    public boolean takeMessage(String s) {
        return false;
    }

    @Override
    public void init() {

    }

    @Override
    public void atViewLoadAfterInit() {

    }

    public void bulidView(String result){

        final OpenLongBoxServer me = this;

        //只要有弹出框立刻清空008009



        this.atv.getActivity().closeAlertBox();
        this.atv.getActivity().lvFloatRightList.setVisibility(View.GONE);





        //测试弹窗高度


        if (me.atv.getActivity().getmAlertText()!= null) {

            me.atv.getActivity().getmAlertText().setVisibility(View.VISIBLE);

//            FontHandler hander = new FontHandler(  this.atv.getActivity() );
//            //由于是弹出窗里的点击URL，所以当点击了URL后需要关闭弹出框
//            //为hander设定回调
//            hander.setClickListener(new com.impl.OnClickListener() {
//                @Override
//                public <T> void onClick(T e) {
//                    me.atv.getActivity().closeAlertBox();
//                    me.atv.getActivity().lvFloatRightList.setVisibility(View.GONE);
//                }
//            });


            LinearLayout.LayoutParams mAlertListLp = new LinearLayout.LayoutParams(0 , LinearLayout.LayoutParams.WRAP_CONTENT);
            me.atv.getActivity().list008Weight = 1;
            mAlertListLp.weight = me.atv.getActivity().list008Weight;
            me.atv.getActivity().getmAlertList().setLayoutParams(mAlertListLp);


                   // me.atv.getActivity().getmAlertText().setText( Html.fromHtml(result,null,hander ) );
            me.atv.getActivity().getmAlertText().setText( this.atv.getActivity().getHtmlSpanner().fromHtml(result) );
            me.atv.getActivity().getmAlertText().setClickable(true);
            me.atv.getActivity().getmAlertText().setMovementMethod(LinkMovementMethod.getInstance());


            //隐藏属于输入框的文字描述


            if(me.atv.getActivity().getmAlertInputBigText()!=null){
                me.atv.getActivity().getmAlertInputBigText().setVisibility(View.GONE);
                me.atv.getActivity().getmAlertInputBigText().setText("");
            }


            if (me.atv.getActivity().getmAlertLayout() != null && me.atv.getActivity().getmAlertLayout().getVisibility() == View.INVISIBLE) {
                me.atv.getActivity().getmAlertLayout().setVisibility(View.VISIBLE);
                me.atv.getActivity().getmAlertLayout().setClickable(true);
                me.atv.getActivity().getmAlertLayout().requestFocus();
            }
            if (me.atv.getActivity().getmInputLayout().getVisibility() == View.VISIBLE) {
                me.atv.getActivity().getmInputLayout().setVisibility(View.INVISIBLE);
                me.atv.getActivity().getmInputLayout().setClickable(false);
            }


//            if(result.contains(MudProtocol.WZOBACTS3)){
//                //当前文本只能被写入到弹出框右边的文本框
//
//
//                String str="";
//                int s1,s2;
//                s1 = result.indexOf(MudProtocol.WZOBACTS3);
//                s2 = result.indexOf("<br>");
//
//                str = result.substring(s1,s2);
//                str.replace("<br>","");
//                str = str.replace(MudProtocol.WZOBACTS3, "");
//                result = result.replace(str, "");
//                result = result.replace(MudProtocol.WZOBACTS3, "");
//                mAlertText.setText(str);
//
//                //LayoutParams m091TvLp = new LayoutParams( FUti.dip2px(this,getApp().getWndWidth()*8 / 100),LayoutParams.WRAP_CONTENT);
//
//                //只要出现右边的文字 那么008必然存在，提前显示008
//                //mAlertList.setVisibility(View.VISIBLE);
//
//
//                //closeAlertBox();
//
//
//                LinearLayout.LayoutParams m091TvLp = new LinearLayout.LayoutParams(0 , LinearLayout.LayoutParams.WRAP_CONTENT);
//                m091TvLp.weight = 30;
//                m091Tv.setLayoutParams(m091TvLp);
//                //只有出现091的时候008设为10
//                LinearLayout.LayoutParams mAlertListLp = new LinearLayout.LayoutParams(0 , LinearLayout.LayoutParams.WRAP_CONTENT);
//                list008Weight = 10;
//                mAlertListLp.weight = list008Weight;
//                mAlertList.setLayoutParams(mAlertListLp);
//                GradientDrawable drawable = (GradientDrawable) m091Tv.getBackground();
//                //边框
//                drawable.setStroke(FUti.dip2px(this,2), Color.parseColor(Constant.getAppColor().getButBorderColor()));
//                //设置背景
//                drawable.setColor(Color.parseColor(Constant.getAppColor().getButBackColor()));
//
//                m091Tv.setVisibility(View.VISIBLE);
//                m091Tv.setText( Html.fromHtml(result,null,hander ) );
//                m091Tv.setClickable(true);
//                m091Tv.setMovementMethod(LinkMovementMethod.getInstance());
//            }else{
//
//
//            }



            //mAlertText.setText(Html.fromHtml(result+"xxxxx"));
        }




    }







}
